const express = require('express');
const bodyParser = require('body-parser');
const mysql = require('mysql2');
const app = express();
app.use(bodyParser.json());
const db = mysql.createConnection({
    host: 'localhost',
    user: 'root',
    password: 'password',
    database: 'login_exam'
});
app.post('/login', (req, res) => {
    const {
        username,
        password
    } = req.body;
    db.query('SELECT * FROM users WHERE username = ? AND password = ?', [username,
        password
    ], (err, results) => {
        if (err) {
            return res.status(500).json({
                success: false,
                message: '服务器错误'
            });
        }
        if (results.length > 0) {
            res.json({
                success: true
            });
        } else {
            res.json({
                success: false,
                message: '用户名或者密码不正确'
            });
        }
    });
});
app.listen(3000, () => {
    console.log('Server running on http://localhost:3000');
});